//
//  GTNavigationController.m
//  GiftTalk
//
//  Created by Wan on 16/3/22.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTNavigationController.h"
#import "GTSettingViewController.h"

@implementation GTNavigationController

+ (void)initialize
{
    UINavigationBar *navigationBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    // 设置NavigationBar背景颜色
    navigationBar.barTintColor = GTThemeColor;
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    attrs[NSFontAttributeName] = [UIFont fontWithName:GTThemeFontName size:20.0];
    // 设置导航控制器标题栏文字属性 & 背景色
    [navigationBar setTitleTextAttributes:attrs];
    //    [navigationBar setBackgroundImage:[UIImage imageNamed:@"post_replybutton_highlighted"] forBarMetrics:UIBarMetricsDefault];
    navigationBar.backgroundColor = GTRGBColor(251, 14, 56);

    // 返回图片和返回按钮颜色
    navigationBar.tintColor = [UIColor whiteColor];

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 如果滑动移除控制器的功能失效，清空代理（让导航控制器重新设置这个功能）
    self.interactivePopGestureRecognizer.delegate = nil;
}

/**
 *  可以在这个方法中,拦截所有 push 进来的控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 如果 push 进来的不是第一个控制器
    if (self.childViewControllers.count > 0) {
        
//        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [backBtn setTitle:@"礼物说" forState: UIControlStateNormal];
//        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
//        [backBtn setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
//        backBtn.size = CGSizeMake(100, 30);
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
    
    // 返回按钮设置
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"礼物说" style:UIBarButtonItemStylePlain target:nil action:nil];
    viewController.navigationItem.backBarButtonItem = backButtonItem;
}



- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

@end
